# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
# Licensed under the MIT License (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
#     http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions and
# limitations under the License.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.

# Generated by Django 3.2.12 on 2022-10-17 04:21

from django.db import migrations, models
import django.db.models.deletion
import paasng.bk_plugins.pluginscenter.constants
import paasng.bk_plugins.pluginscenter.models.definitions
import paasng.bk_plugins.pluginscenter.models.instances
import paasng.utils.models
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name='PluginDefinition',
            fields=[
                (
                    'uuid',
                    models.UUIDField(
                        auto_created=True,
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                        verbose_name='UUID',
                    ),
                ),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('identifier', models.CharField(max_length=64, unique=True)),
                ('name_zh_cn', models.CharField(max_length=64, verbose_name='name')),
                ('name_en', models.CharField(blank=True, max_length=64, verbose_name='name')),
                ('description_zh_cn', models.TextField(verbose_name='description')),
                ('description_en', models.TextField(blank=True, verbose_name='description')),
                ('docs', models.CharField(max_length=255)),
                ('logo', models.CharField(max_length=255)),
                ('administrator', models.JSONField()),
                ('approval_config', paasng.bk_plugins.pluginscenter.models.definitions.PluginCreateApprovalField()),
                (
                    'release_revision',
                    paasng.bk_plugins.pluginscenter.models.definitions.ReleaseRevisionDefinitionField(),
                ),
                ('release_stages', paasng.bk_plugins.pluginscenter.models.definitions.ReleaseStageDefinitionField()),
                ('log_config', paasng.bk_plugins.pluginscenter.models.definitions.PluginLogConfigField(null=True)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PluginInstance',
            fields=[
                (
                    'uuid',
                    models.UUIDField(
                        auto_created=True,
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                        verbose_name='UUID',
                    ),
                ),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('id', models.CharField(max_length=32)),
                ('name_zh_cn', models.CharField(max_length=32, verbose_name='name')),
                ('name_en', models.CharField(blank=True, max_length=32, verbose_name='name')),
                ('template', paasng.bk_plugins.pluginscenter.models.instances.PluginCodeTemplateField()),
                ('extra_fields', models.JSONField(verbose_name='额外字段')),
                ('language', models.CharField(help_text='冗余字段, 用于减少查询次数', max_length=16, verbose_name='开发语言')),
                ('repo_type', models.CharField(max_length=16, null=True, verbose_name='源码托管类型')),
                ('repository', models.CharField(max_length=255)),
                (
                    'status',
                    models.CharField(
                        choices=[
                            ('waiting-approval', '创建审批中'),
                            ('developing', '开发中'),
                            ('releasing', '发布中'),
                            ('released', '已发布'),
                        ],
                        default=paasng.bk_plugins.pluginscenter.constants.PluginStatus['WAITING_APPROVAL'],
                        max_length=16,
                        verbose_name='插件状态',
                    ),
                ),
                ('creator', paasng.utils.models.BkUserField(blank=True, db_index=True, max_length=64, null=True)),
                (
                    'pd',
                    models.ForeignKey(
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to='pluginscenter.plugindefinition',
                    ),
                ),
            ],
            options={
                'unique_together': {('pd', 'id')},
            },
        ),
        migrations.CreateModel(
            name='PluginRelease',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('type', models.CharField(max_length=16, verbose_name='版本类型(正式/测试)')),
                ('version', models.CharField(max_length=255, verbose_name='版本号')),
                ('comment', models.TextField(verbose_name='版本日志')),
                ('extra_fields', models.JSONField(verbose_name='额外字段')),
                (
                    'semver_type',
                    models.CharField(help_text='该字段只用于自动生成版本号的插件', max_length=16, null=True, verbose_name='语义化版本类型'),
                ),
                ('source_location', models.CharField(max_length=2048, verbose_name='代码仓库地址')),
                (
                    'source_version_type',
                    models.CharField(max_length=128, null=True, verbose_name='代码版本类型(branch/tag)'),
                ),
                ('source_version_name', models.CharField(max_length=128, null=True, verbose_name='代码分支名/tag名')),
                ('source_hash', models.CharField(max_length=128, verbose_name='代码提交哈希')),
                (
                    'stages_shortcut',
                    paasng.bk_plugins.pluginscenter.models.instances.StagesShortcutField(
                        default=[], help_text='发布阶段简易索引(保证顺序可靠)', null=True
                    ),
                ),
                (
                    'status',
                    models.CharField(
                        default=paasng.bk_plugins.pluginscenter.constants.PluginReleaseStatus['INITIAL'], max_length=16
                    ),
                ),
                ('tag', models.CharField(db_index=True, max_length=16, null=True, verbose_name='标签')),
                ('creator', paasng.utils.models.BkUserField(blank=True, db_index=True, max_length=64, null=True)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PluginReleaseStage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('stage_id', models.CharField(max_length=32, verbose_name='阶段标识')),
                ('stage_name', models.CharField(help_text='冗余字段, 用于减少查询次数', max_length=16, verbose_name='阶段名称')),
                ('invoke_method', models.CharField(help_text='冗余字段, 用于减少查询次数', max_length=16, verbose_name='触发方式')),
                (
                    'status',
                    models.CharField(
                        default=paasng.bk_plugins.pluginscenter.constants.PluginReleaseStatus['INITIAL'],
                        max_length=16,
                        verbose_name='发布状态',
                    ),
                ),
                ('fail_message', models.TextField(verbose_name='错误原因')),
                (
                    'itsm_detail',
                    models.JSONField(help_text='该字段仅 invoke_method = itsm 时可用', null=True, verbose_name='ITSM 详情'),
                ),
                (
                    'api_detail',
                    models.JSONField(help_text='该字段仅 invoke_method = api 时可用', null=True, verbose_name='API 详情'),
                ),
                (
                    'next_stage',
                    models.OneToOneField(
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to='pluginscenter.pluginreleasestage',
                    ),
                ),
                (
                    'release',
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='all_stages',
                        to='pluginscenter.pluginrelease',
                    ),
                ),
            ],
            options={
                'unique_together': {('release', 'stage_id')},
            },
        ),
        migrations.AddField(
            model_name='pluginrelease',
            name='current_stage',
            field=models.OneToOneField(
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to='pluginscenter.pluginreleasestage',
            ),
        ),
        migrations.AddField(
            model_name='pluginrelease',
            name='plugin',
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.CASCADE,
                related_name='all_versions',
                to='pluginscenter.plugininstance',
            ),
        ),
        migrations.CreateModel(
            name='PluginMembership',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('user', paasng.utils.models.BkUserField(blank=True, db_index=True, max_length=64, null=True)),
                ('role', models.IntegerField(default=3)),
                (
                    'plugin',
                    models.ForeignKey(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        to='pluginscenter.plugininstance',
                    ),
                ),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PluginMarketInfoDefinition',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('storage', models.CharField(max_length=16, verbose_name='存储方式')),
                ('category', paasng.bk_plugins.pluginscenter.models.definitions.PluginBackendAPIResourceField()),
                ('api', paasng.bk_plugins.pluginscenter.models.definitions.PluginBackendAPIField(null=True)),
                (
                    'extra_fields',
                    paasng.bk_plugins.pluginscenter.models.definitions.PluginExtraFieldField(default=dict),
                ),
                (
                    'pd',
                    models.OneToOneField(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='market_info_definition',
                        to='pluginscenter.plugindefinition',
                    ),
                ),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PluginMarketInfo',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('category', models.CharField(db_index=True, max_length=16, verbose_name='分类')),
                ('introduction_zh_cn', models.CharField(max_length=255, verbose_name='简介')),
                ('introduction_en', models.CharField(blank=True, max_length=255, verbose_name='简介')),
                ('description_zh_cn', models.TextField(null=True, verbose_name='详细描述')),
                ('description_en', models.TextField(blank=True, null=True, verbose_name='详细描述')),
                ('contact', models.TextField(help_text='以分号(;)分割', verbose_name='联系人')),
                ('extra_fields', models.JSONField(verbose_name='额外字段')),
                (
                    'plugin',
                    models.OneToOneField(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        to='pluginscenter.plugininstance',
                    ),
                ),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PluginBasicInfoDefinition',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('id_schema', paasng.bk_plugins.pluginscenter.models.definitions.FieldSchemaField()),
                ('name_schema', paasng.bk_plugins.pluginscenter.models.definitions.FieldSchemaField()),
                (
                    'init_templates',
                    paasng.bk_plugins.pluginscenter.models.definitions.PluginCodeTemplateListField(help_text='初始化模板'),
                ),
                ('release_method', models.CharField(max_length=16, verbose_name='发布方式')),
                ('repository_group', models.CharField(max_length=255, verbose_name='插件代码初始化仓库组')),
                ('api', paasng.bk_plugins.pluginscenter.models.definitions.PluginBackendAPIField()),
                (
                    'extra_fields',
                    paasng.bk_plugins.pluginscenter.models.definitions.PluginExtraFieldField(default=dict),
                ),
                (
                    'pd',
                    models.OneToOneField(
                        db_constraint=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='basic_info_definition',
                        to='pluginscenter.plugindefinition',
                    ),
                ),
            ],
            options={
                'abstract': False,
            },
        ),
    ]
